#include "common.hpp"

static const char *optString = "h?";

static const struct option longOpts[] = {
    { "help", no_argument, NULL, 'h' }
};

int main (int argc, char* const argv[]) {
	ipc::semaphore mutex( ftok(BASE_NAME,10),0 );
	ipc::shared_memory<sGimnasio> gim( ftok(BASE_NAME,11) );

	ipc::messages_queue cola1 ( ftok(BASE_NAME,16) );
	ipc::messages_queue cola2 ( ftok(BASE_NAME,17) );
	
	int longIndex = 0;
	int option = 0;
	while ( (option = getopt_long(argc,argv,optString,longOpts,&longIndex) ) != EOF ) {
		switch (option) {
			case '?':
			case 'h':
			case ':':
				std::cerr << "Proceso para liberación del entorno de ejecución." << std::endl;
				std::cerr << "\tUso: " << argv[0] << " [-h]" << std::endl;
				std::cerr << "\tParametros:" << std::endl;
				std::cerr << "\t\t-h,--help:\tMostrar este mensaje de ayuda." << std::endl;

				return 0;
			default:
				break;
		}
	}

	if (mutex.get(PERMITS) == 0)
		mutex.destroy();

	if ( gim.get(PERMITS) == 0)
		gim.destroy();

	if ( cola1.get(PERMITS) == 0)
		cola1.destroy();
	if ( cola2.get(PERMITS) == 0)
		cola2.destroy();

	return 0;
}

